package bytestream;

import java.io.*;

public class FileOutputStreamWRImageDemo {

    public static void main(String[] args) {
        File srcFile = new File("d:" + File.separator + "java_logo.jpg");
        File dest = new File("d:" + File.separator + "dest.jpg");
        InputStream fin = null;
        OutputStream fout = null;
        try {
            fin = new FileInputStream(srcFile);
            fout = new FileOutputStream(dest);
            long startTime = System.currentTimeMillis();

            //一边读，一边写
            int data = -1;
            while ((data = fin.read()) != -1) {
                fout.write(data);
            }
            long endTime = System.currentTimeMillis();
            System.out.println("总用时：" + (endTime - startTime) + "毫秒");

        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            if (fin != null) {
                try {
                    fin.close();
                    fin = null;
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fout != null) {
                try {
                    fout.close();
                    fout = null;
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
